package com.example.papercut.controller;

import com.example.papercut.entity.TextureTemplate;
import com.example.papercut.service.TextureTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/templates/texture")
public class TextureTemplateController {

    private final TextureTemplateService textureService;

    @Autowired
    public TextureTemplateController(TextureTemplateService textureService) {
        this.textureService = textureService;
    }

    /**
     * GET /api/templates/texture/{id}
     * 2.2: 获取指定 ID 的纹理模板详情
     */
    @GetMapping("/{id}")
    public ResponseEntity<TextureTemplate> getTextureDetails(@PathVariable Integer id) {
        TextureTemplate texture = textureService.getTextureDetails(id);
        if (texture == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(texture);
    }

    /**
     * GET /api/templates/texture?categoryId=5
     * 2.2: 获取所有纹理模板，可筛选
     */
    @GetMapping
    public ResponseEntity<List<TextureTemplate>> getAllTextures(
        @RequestParam(required = false) Integer categoryId) {
        
        List<TextureTemplate> textures = textureService.getAllTextures(categoryId);
        return ResponseEntity.ok(textures);
    }
}